<!DOCTYPE html>
<html lang="zh-Hans">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<meta name="theme-color" content="#222"><meta name="generator" content="Hexo 6.2.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/vhuichen.ico">
  <link rel="icon" type="image/png" sizes="32x32" href="/vhuichen.ico">
  <link rel="icon" type="image/png" sizes="16x16" href="/vhuichen.ico">
  <link rel="mask-icon" href="/vhuichen.ico" color="#222">

<link rel="stylesheet" href="/css/main.css">



<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.0/css/all.min.css" integrity="sha256-AbA177XfpSnFEvgpYu1jMygiLabzPCJCRIBtR5jGc0k=" crossorigin="anonymous">
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.1.1/animate.min.css" integrity="sha256-PR7ttpcvz8qrF57fur/yAx1qXMFJeJFiA6pSzWi0OIE=" crossorigin="anonymous">

<script class="next-config" data-name="main" type="application/json">{"hostname":"vhuichen.github.io","root":"/","images":"/images","scheme":"Pisces","darkmode":false,"version":"8.13.0","exturl":false,"sidebar":{"position":"left","display":"display","padding":18,"offset":12},"copycode":{"enable":false,"style":null},"bookmark":{"enable":false,"color":"#222","save":"auto"},"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"stickytabs":false,"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"Searching...","empty":"We didn't find any results for the search: ${query}","hits_time":"${hits} results found in ${time} ms","hits":"${hits} results found"}}</script><script src="/js/config.js"></script>

    <meta name="description" content="什么是ABI应用程序二进制接口（Application Binary Interface，ABI）是指两程序模块间的接口，通常其中一个程序模块会是库或操作系统所提供的服务，而另一边的模块则是用户所运行的程序。ABI 约定了我们的应用程序怎样获取数据以及操作数据。应用程序就是通过这些ABI跟系统通信的。 ABI稳定Swift 5.0 版本之前，应用程序打包时，都会将 Swift 标准库导入到二进制包">
<meta property="og:type" content="article">
<meta property="og:title" content="Swift 什么是ABI稳定、模块稳定">
<meta property="og:url" content="https://vhuichen.github.io/2020/05/Swift/%E5%9F%BA%E7%A1%80/Swift%20%E4%BB%80%E4%B9%88%E6%98%AFABI%E7%A8%B3%E5%AE%9A%E3%80%81%E6%A8%A1%E5%9D%97%E7%A8%B3%E5%AE%9A/index.html">
<meta property="og:site_name" content="vhuichen">
<meta property="og:description" content="什么是ABI应用程序二进制接口（Application Binary Interface，ABI）是指两程序模块间的接口，通常其中一个程序模块会是库或操作系统所提供的服务，而另一边的模块则是用户所运行的程序。ABI 约定了我们的应用程序怎样获取数据以及操作数据。应用程序就是通过这些ABI跟系统通信的。 ABI稳定Swift 5.0 版本之前，应用程序打包时，都会将 Swift 标准库导入到二进制包">
<meta property="og:locale">
<meta property="og:image" content="https://gitee.com/vhuichen/images/raw/master/img/20210513181627.png">
<meta property="article:published_time" content="2020-05-09T16:00:00.000Z">
<meta property="article:modified_time" content="2021-07-03T17:18:40.059Z">
<meta property="article:author" content="vhuichen">
<meta property="article:tag" content="Swift">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/vhuichen/images/raw/master/img/20210513181627.png">


<link rel="canonical" href="https://vhuichen.github.io/2020/05/Swift/%E5%9F%BA%E7%A1%80/Swift%20%E4%BB%80%E4%B9%88%E6%98%AFABI%E7%A8%B3%E5%AE%9A%E3%80%81%E6%A8%A1%E5%9D%97%E7%A8%B3%E5%AE%9A/">



<script class="next-config" data-name="page" type="application/json">{"sidebar":"","isHome":false,"isPost":true,"lang":"zh-Hans","comments":true,"permalink":"https://vhuichen.github.io/2020/05/Swift/%E5%9F%BA%E7%A1%80/Swift%20%E4%BB%80%E4%B9%88%E6%98%AFABI%E7%A8%B3%E5%AE%9A%E3%80%81%E6%A8%A1%E5%9D%97%E7%A8%B3%E5%AE%9A/","path":"2020/05/Swift/基础/Swift 什么是ABI稳定、模块稳定/","title":"Swift 什么是ABI稳定、模块稳定"}</script>

<script class="next-config" data-name="calendar" type="application/json">""</script>
<title>Swift 什么是ABI稳定、模块稳定 | vhuichen</title>
  






  <noscript>
    <link rel="stylesheet" href="/css/noscript.css">
  </noscript>
</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="Toggle navigation bar" role="button">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <i class="logo-line"></i>
      <p class="site-title">vhuichen</p>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">记录、分享</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu"><li class="menu-item menu-item-home"><a href="/" rel="section">Home</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section">Archives</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section">About</a></li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle" role="button">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          Table of Contents
        </li>
        <li class="sidebar-nav-overview">
          Overview
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <div class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E6%98%AFABI"><span class="nav-number">1.</span> <span class="nav-text">什么是ABI</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#ABI%E7%A8%B3%E5%AE%9A"><span class="nav-number">2.</span> <span class="nav-text">ABI稳定</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%A8%A1%E5%9D%97%E7%A8%B3%E5%AE%9A"><span class="nav-number">3.</span> <span class="nav-text">模块稳定</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E4%BB%80%E4%B9%88%E6%98%AF-Library-Evolution"><span class="nav-number">3.0.1.</span> <span class="nav-text">什么是 Library Evolution</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%8F%82%E8%80%83"><span class="nav-number">4.</span> <span class="nav-text">参考</span></a></li></ol></div>
        </div>
        <!--/noindex-->

        <div class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="vhuichen"
      src="/images/vhuichen.jpg">
  <p class="site-author-name" itemprop="name">vhuichen</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
        <a href="/archives/">
          <span class="site-state-item-count">78</span>
          <span class="site-state-item-name">posts</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
          <a href="/categories/">
        <span class="site-state-item-count">11</span>
        <span class="site-state-item-name">categories</span></a>
      </div>
      <div class="site-state-item site-state-tags">
          <a href="/tags/">
        <span class="site-state-item-count">86</span>
        <span class="site-state-item-name">tags</span></a>
      </div>
  </nav>
</div>



        </div>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top" role="button" aria-label="Back to top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">


  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-Hans">
    <link itemprop="mainEntityOfPage" href="https://vhuichen.github.io/2020/05/Swift/%E5%9F%BA%E7%A1%80/Swift%20%E4%BB%80%E4%B9%88%E6%98%AFABI%E7%A8%B3%E5%AE%9A%E3%80%81%E6%A8%A1%E5%9D%97%E7%A8%B3%E5%AE%9A/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/vhuichen.jpg">
      <meta itemprop="name" content="vhuichen">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="vhuichen">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="post" itemscope itemtype="http://schema.org/CreativeWork">
      <meta itemprop="name" content="Swift 什么是ABI稳定、模块稳定 | vhuichen">
      <meta itemprop="description" content="">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          Swift 什么是ABI稳定、模块稳定
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">Posted on</span>

      <time title="Created: 2020-05-10 00:00:00" itemprop="dateCreated datePublished" datetime="2020-05-10T00:00:00+08:00">2020-05-10</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar-check"></i>
      </span>
      <span class="post-meta-item-text">Edited on</span>
      <time title="Modified: 2021-07-04 01:18:40" itemprop="dateModified" datetime="2021-07-04T01:18:40+08:00">2021-07-04</time>
    </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">In</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/categories/Swift/" itemprop="url" rel="index"><span itemprop="name">Swift</span></a>
        </span>
    </span>

  
</div>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h3 id="什么是ABI"><a href="#什么是ABI" class="headerlink" title="什么是ABI"></a>什么是ABI</h3><p>应用程序二进制接口（Application Binary Interface，ABI）是指两程序模块间的接口，通常其中一个程序模块会是库或操作系统所提供的服务，而另一边的模块则是用户所运行的程序。<br>ABI 约定了我们的应用程序怎样获取数据以及操作数据。应用程序就是通过这些ABI跟系统通信的。</p>
<h3 id="ABI稳定"><a href="#ABI稳定" class="headerlink" title="ABI稳定"></a>ABI稳定</h3><p>Swift 5.0 版本之前，应用程序打包时，都会将 Swift 标准库导入到二进制包中，原因是不同的 Swift 版本之间差异大，ABI接口不兼容。<br>Swift 5.0 开始 ABI 以及稳定。从 5.0 版本开始 Swift 共用一个 ABI 接口，所以从 5.0 版本开始打包时就不需要将 SWift 基础库打进二进制包中，此时iOS系统以及包含了这些基础库，这样做的好处是之一就是包体积变小了，启动时间变少了，更省内存了。</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">事实上，打包时还是会包含 Swift 基础库，原因是在 iOS 12.2 之前依然需要 Swift 基础库，但之后的版本 App Store 会自动移除。</span><br></pre></td></tr></table></figure>

<h3 id="模块稳定"><a href="#模块稳定" class="headerlink" title="模块稳定"></a>模块稳定</h3><p>Swift 5.1 之前，不同的版本生成的 Module（模块）只能在对应的版本上运行，不然就会出现以下错误</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">Module compiled with Swift 5.0.1 cannot be imported by the Swift 5.1 compiler</span><br></pre></td></tr></table></figure>

<p>而从 5.1 版本开始， <code>Module Stability</code> 允许 5.1 版本打的 Module 在 5.1 之后的任意版本运行。</p>
<p>开启 <code>Module Stability</code> 后，Framework 引入了一个全新的文件夹 <code>.swiftmodule</code>，包含 <code>.swiftinterface</code> 和 <code>.swiftmodule</code> 文件，<code>swiftinterface</code> 文件作为 <code>swiftmodule</code> 的一个补充，用来描述 <code>module</code> 公开接口的文本文件，并且不受编译器版本限制，既通过 <code>swiftinterface</code> 文件可以将 Swift 6 打包的 framework 在 swift 7 版本下运行。</p>
<p>需要设置 </p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">//BUILD_LIBRARY_FOR_DISTRIBUTION</span><br><span class="line">//Ensures that your libraries are built for distribution. </span><br><span class="line">//For Swift, this enables support for library evolution and generation of a module interface file.</span><br><span class="line">Build Libraries for Distribution = YES</span><br></pre></td></tr></table></figure>

<p>开启 <code>Build Libraries for Distribution</code> 后编译的文件如下<br><img src="https://gitee.com/vhuichen/images/raw/master/img/20210513181627.png"></p>
<p>如果不开启 <code>Build Libraries for Distribution</code> ，那么编译后会少了 <code>swiftinterface</code>， 此时的 <code>Module</code> 是受版本限制的。</p>
<h5 id="什么是-Library-Evolution"><a href="#什么是-Library-Evolution" class="headerlink" title="什么是 Library Evolution"></a>什么是 Library Evolution</h5><p>开启 <code>Library Evolution</code> 后，也就是<code>Build Libraries for Distribution</code>，当一个框架依赖另一个框架时，如果另一个框架发生改动，那么不需要重新编译第一个框架。也就是更新第二个框架不需要重新编译第一个框架。<br>类似于 <code>@frozen</code> ?</p>
<h3 id="参考"><a href="#参考" class="headerlink" title="参考"></a>参考</h3><p><a target="_blank" rel="noopener" href="https://onevcat.com/2019/02/swift-abi/">Swift ABI 稳定对我们到底意味着什么</a><br><a target="_blank" rel="noopener" href="https://swift.org/blog/abi-stability-and-more/">ABI Stability and More</a><br><a target="_blank" rel="noopener" href="https://www.donnywals.com/what-is-module-stability-in-swift-and-why-should-you-care/">What is Module Stability in Swift and why should you care?</a></p>

    </div>

    
    
    

    <footer class="post-footer">
          <div class="post-tags">
              <a href="/tags/Swift/" rel="tag"># Swift</a>
          </div>

        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/2020/05/iOS/CocoaPods%E4%B9%8BProfile/" rel="prev" title="CocoaPods之Profile">
                  <i class="fa fa-chevron-left"></i> CocoaPods之Profile
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/2020/08/Swift/%E5%9F%BA%E7%A1%80/Swift%20as%20as!%20as?%20%E7%9A%84%E7%90%86%E8%A7%A3/" rel="next" title="Swift as as! as? 的理解">
                  Swift as as! as? 的理解 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






</div>
  </main>

  <footer class="footer">
    <div class="footer-inner">


<div class="copyright">
  &copy; 2015 – 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">vhuichen</span>
</div>
  <div class="powered-by">Powered by <a href="https://hexo.io/" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/pisces/" rel="noopener" target="_blank">NexT.Pisces</a>
  </div>

    </div>
  </footer>

  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/animejs/3.2.1/anime.min.js" integrity="sha256-XL2inqUJaslATFnHdJOi9GfQ60on8Wx1C2H8DYiN1xY=" crossorigin="anonymous"></script>
<script src="/js/comments.js"></script><script src="/js/utils.js"></script><script src="/js/motion.js"></script><script src="/js/next-boot.js"></script>

  





  





</body>
</html>
